﻿Imports Models.Security
Imports System.ComponentModel.DataAnnotations

Namespace Users

    Public Class UserVO
        Inherits BaseVO

        Private _userId As Integer
        Private _fullName As String
        Private _login As String
        Private _password As String
        Private _email As String
        Private _active As Boolean

        Private _userCompanies As New Generic.List(Of UserCompanyVO)

        Sub New()
        End Sub

        Sub New(entity As Data.BaseModel.User, Optional skipLoadUsers As Boolean = False)
            If entity IsNot Nothing Then
                userId = entity.UserId
                fullName = entity.FullName
                login = entity.Login
                password = entity.Password
                active = entity.Active
                email = entity.Email

                ' Agregar el listado de grupos
                If Not skipLoadUsers AndAlso entity.UserCompanies IsNot Nothing Then
                    For Each oItem As Data.BaseModel.UserCompany In entity.UserCompanies
                        userCompanies.Add(New UserCompanyVO(oItem, True))
                    Next
                End If
            End If
        End Sub

        Public Property userId As Integer
            Get
                Return _userId
            End Get
            Set(value As Integer)
                _userId = value
            End Set
        End Property

        <StringLengthAtt(50, "fullName", 3)> _
        Public Property fullName As String
            Get
                Return _fullName
            End Get
            Set(value As String)
                _fullName = value
            End Set
        End Property

        <StringLengthAtt(50, "login", 3)> _
        Public Property login As String
            Get
                Return _login
            End Get
            Set(value As String)
                _login = value
            End Set
        End Property

        <PasswordAtt(6, "password", 15)> _
        Public Property password() As String
            Get
                Return _password
            End Get
            Set(ByVal value As String)
                _password = value
            End Set
        End Property

        <EmailAddressAtt("email")> _
        Public Property email() As String
            Get
                Return _email
            End Get
            Set(ByVal value As String)
                _email = value
            End Set
        End Property

        Public Property active() As Boolean
            Get
                Return _active
            End Get
            Set(ByVal value As Boolean)
                _active = value
            End Set
        End Property

        Public Property userCompanies As Generic.List(Of UserCompanyVO)
            Get
                Return _userCompanies
            End Get
            Set(ByVal value As Generic.List(Of UserCompanyVO))
                _userCompanies = value
            End Set
        End Property

    End Class

End Namespace